angular.module('${menuCode}')
.filter('to_trusted', ['$sce', function ($sce) {
	return function (text) {
	    return $sce.trustAsHtml(text);
	};
}])
.controller("${widgetCode}Ctrl",function($scope,AppKit,$stateParams,$ionicActionSheet,$state,$ionicHistory){
	//加载数据
	$scope.loadIntentFollowupInfoData = function(){
		var url = '/aeaicrm/services/MyTasks/rest/intention-info/'+$stateParams.taskId;
		AppKit.getJsonApi(url).success(function(rspJson){
			$scope.customerInfo = rspJson;
		});	
	}
	$scope.loadIntentFollowupInfoData();
	//编辑保存
	$scope.updateSave = function(){
		var url = "/aeaicrm/services/ProCustomer/rest/add-cust-info/";
		AppKit.postJsonApi(url,JSON.stringify($scope.customerInfo)).then(function(response){
			if ("success" == response.data){
				AppKit.successPopup({"title":"保存成功!"});
				$state.go("tab.potential-customer-list",{},{reload:true});
			}else{
				AppKit.errorPopup({"title":"保存失败!"});
				$state.go("tab.potential-customer-list",{},{reload:true});
			}
		});
	}
	//删除客户信息
	$scope.deleteCustomerInfo = function(){
		var url = "/aeaicrm/services/ProCustomer/rest/delete-visit-info/"+$stateParams.infoId;
		AppKit.getJsonApi(url).success(function(rspJson){
			if ("success" == rspJson){
				AppKit.successPopup({"title":"删除成功!"});
				$state.go("tab.potential-customer-list");
			}else{
				AppKit.errorPopup({"title":"删除失败!"});
				$state.go("tab.potential-customer-list",{},{reload:true});
			}
		});
	}
	//打开拜访记录模态
	$scope.openMyTasksVisitModal = function(id,category) {
		$scope.visitId = id;
		$scope.visitCategory = category;
		AppKit.createModal("${menuCode}","TasksIntentFollowupRecordModal",$scope);
	}
	
	$scope.showActionSheet = function() {
	      var hideSheet = $ionicActionSheet.show({
	          buttons: [
	            { text: '<b>无意向</b>'  },
	            { text: '<b>再跟进</b>'  },
	            { text: '<b>编辑客户</b>'  }
	          ],
	          titleText: '请选择您的操作',
	          cancelText: '取消',
	          cancel: function() {
	               // add cancel code..
	          },
	          buttonClicked: function(index) {
	        	  if(index==0){
	        		  $state.go("tab.nointent-info",{"orgSalesman": $scope.customerInfo.orgSalesman});
	        	  }
	        	  else if(index==1){
	        		  $state.go("tab.againfollowup-info",{"orgSalesman": $scope.customerInfo.orgSalesman});
	        	  }
	        	  else if(index==2){
	        		  $state.go("tab.my-customer-information",{"id": $stateParams.custId}); 
	        	  }
	            return true; 
	          }
	      });
	  };
});